<?php
/**
 *-----------------  （慕课网）《Yii框架》不得不说的故事  -----------------
 * Author: Zheng_Great
 * Description:  yii 事件学习
 * Date: 2017-03-30 13:27:24
 */


namespace frontend\controllers;

use yii;
use yii\base\Event;
use yii\web\Controller;
use frontend\helps\events\Cat;
use frontend\helps\events\Mourse;
use frontend\helps\events\Dog;


class EventController extends Controller{

	public function actionIndex(){

		$cat=new Cat();

		$dog=new Dog();	
		$mourse=new Mourse();

		//绑定事件
		$cat->on('miao',[$mourse,'run']);
		$cat->on('miao',[$dog,'look']);

		//取消绑定
		// $cat->off('miao',[$dog,'look']);

		//类级别的 事件绑定
		// Event::on(Cat::ClassName(),'miao',[$mourse,'run']);


		//匿名函数的 绑定
		// Event::on(Cat::ClassName(),'miao',function(){
		// 	echo 'miao 事件触发 成功';
		// });

		$cat->shout();

	}




}



 ?>